package com.blog.blog.mapper;

import com.blog.blog.dto.ArticleListQueryDTO;
import com.blog.blog.vo.ArticleListItemVO;
import com.blog.blog.vo.ArticleDetailVO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface ArticleMapper {

    List<ArticleListItemVO> selectByQuery(ArticleListQueryDTO query);

    ArticleDetailVO selectDetailById(Long id);

    long countByQuery(ArticleListQueryDTO query);

    int increaseLikeCount(Long id);

    int increaseViewCount(Long id);
    int increaseViewCountBy(@Param("id") Long id, @Param("delta") Integer delta);

    int increaseCommentCount(Long id);

    /**
     * 查询相关文章（按同分类与标签重合度打分，倒序返回）。
     */
    List<ArticleListItemVO> selectRelated(@Param("id") Long id, @Param("limit") Integer limit);

    /**
     * 查询热门文章（按阅读量倒序、时间倒序）。可选范围与时间窗。
     */
    java.util.List<ArticleListItemVO> selectHot(@Param("limit") Integer limit,
                                               @Param("categoryId") Long categoryId,
                                               @Param("tagId") Long tagId,
                                               @Param("sinceDays") Integer sinceDays);

    // 归档与热门分页
    java.util.List<com.blog.blog.vo.ArticleArchiveItemVO> selectArchives(Integer limit);
    java.util.List<com.blog.blog.vo.ArticleArchiveItemVO> selectArchivesPage(@Param("offset") Integer offset,
                                                                             @Param("limit") Integer limit);
    long countArchives();
    java.util.List<ArticleListItemVO> selectHotPage(@Param("categoryId") Long categoryId,
                                                    @Param("tagId") Long tagId,
                                                    @Param("sinceDays") Integer sinceDays,
                                                    @Param("offset") Integer offset,
                                                    @Param("limit") Integer limit);
    long countHot(@Param("categoryId") Long categoryId,
                  @Param("tagId") Long tagId,
                  @Param("sinceDays") Integer sinceDays);

    // RSS/Feed：最近发布的文章（按时间倒序）
    java.util.List<com.blog.blog.vo.ArticleListItemVO> selectRecentPublished(Integer limit);

    // 站点地图（仅发布）分页
    java.util.List<com.blog.blog.vo.ArticleListItemVO> selectPublishedForSitemap(@Param("offset") Integer offset,
                                                                                @Param("limit") Integer limit);
    long countPublished();

    // 管理端 CRUD
    int insertArticle(com.blog.blog.po.ArticlePO po);
    int updateArticle(com.blog.blog.po.ArticlePO po);
    int deleteArticle(Long id);

    // 标签关联
    int deleteArticleTags(Long articleId);
    int insertArticleTag(@Param("articleId") Long articleId, @Param("tagId") Long tagId);
}


